<template>
  <div class="flex flex-col h-full">
    <SearchContainer show-export @search="getData" @reset="() => formRef.resetFields()" @export="exportRef.$el.querySelector('button').click()">
      <a-form ref="formRef" class="form-style-flex" :model="formState" :label-col="{ style: { width: '80px' } }">
        <a-form-item name="dateRange" label="建档日期">
          <a-range-picker v-model:value="formState.dateRange" format="YYYY-MM-DD" value-format="YYYY-MM-DD" />
        </a-form-item>
        <a-form-item name="zjm" label="就诊事项" class="w-[260px] ml-3">
          <a-select v-model:value="formState.zjm" placeholder="请选择就诊事项" allow-clear>
            <a-select-option v-for="(item, index) in dictOutList" :key="index" :value="item.dictOutpMatterId">{{ item.matterName }}</a-select-option>
          </a-select>
        </a-form-item>
      </a-form>
    </SearchContainer>
    <a-card class="flex-1">
      <a-space ref="exportRef" class="hidden">
        <BaseExport type="报表" name="接待情况统计" code="000441" is-show-time :search-params="formState">导出</BaseExport>
      </a-space>
      <BaseTable :scroll="{ x: 3000 }" :loading="loading" :data-source="tableData" fill column-code="000441">
        <template #bodyCell="{ column, index }">
          <template v-if="column.dataIndex === 'xh'">
            {{ index + 1 }}
          </template>
        </template>
      </BaseTable>
    </a-card>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import dayjs from 'dayjs'
import { message } from 'ant-design-vue'
import SearchContainer from '@/components/SearchContainer'
import BaseTable from '@/components/BaseTable'

const exportRef = ref(null)
const formRef = ref(null)
const dictOutList = ref([])
const formState = ref({
  dateRange: [dayjs().subtract(20, 'day').format('YYYY-MM-DD'), dayjs().format('YYYY-MM-DD')],
  zjm: undefined
})
const { loading, tableData, getData } = useTable({
  url: '/statistic/getdoctorAppointmentSeven',
  params: formState.value,
  formatParams: () => {
    return {
      stdate: formState.value.dateRange?.[0],
      eddate: formState.value.dateRange?.[1],
      zjm: formState.value.zjm
    }
  },
  pagination: false,
  immediate: true
})
// 获取就诊事项
const getDictOutList = async () => {
  const res = await post('/outp/mzdj/getDictOutpMatterNumberList')
  if (res.code !== 0) return message.error(res.msg)
  dictOutList.value = res.data
}
onMounted(() => {
  getDictOutList()
})
</script>
